<%@ page contentType="text/html; charset=UTF-8" %>
<%@page import="com.infomanage.enums.*"%>
<%@page import="com.infomanage.service.hr.*"%>
<%@page import="com.infomanage.po.*" %>
<%@page import="com.infomanage.vo.*" %>
<%  response.addDateHeader("Expires", 0);response.setHeader("Pragma","no-cache"); response.setHeader("Cache-Control","no-cache");%>
<%
	request.setCharacterEncoding("UTF-8");
	User user = (User)session.getAttribute(com.infomanage.util.Consts.LOGINED_USER);
	
	int assDeptId = user.getAssociatedDept();
	int assDeptLevel = user.getDeptLevel();
	
	String personInfoId = request.getParameter("personId");
	if(personInfoId == null) personInfoId = "";
	PersonItem item  = PersonManageService.loadPersonBaseInfo(request, response, out);
	int adminlevel = TechnicDegreeType.ENGINEER.value();
	String birthDate = "";
	String birthPlace = "";
	int bloodType = BloodType.A.value();
	int deptId = -1;
	int highestDigree = -1;
	String hukouPlace = "";
	String idNumber = "";
	String joinWay = "";
	String joinWorkYear = "";
	String name = "";
	String national = "";
	String nativePlace = "";
	int personId = -1;
	String politicalFace = "";
	int position = -1;
	int sex = SexType.MAN.value();
	int techlevel = -1;
	String workerUser = "";
	String workyear = "";
	String deptName = "";
	String phoneNo = "";
	if(item != null){
		Person person = item.getBean();
		Department dept = item.getDept();
		adminlevel = person.getAdminlevel();
		birthDate = person.getBirthDate();
		birthPlace = person.getBirthPlace();
		bloodType = person.getBloodType();
		deptId = person.getDeptId();
		deptName = dept.getPath();
		highestDigree = person.getHighestDigree();
		hukouPlace = person.getHukouPlace();
		idNumber = person.getIdNumber();
		joinWay = person.getJoinWay();
		joinWorkYear = person.getJoinWorkyear();
		name = person.getName();
		national = person.getNational();
		nativePlace = person.getNativePlace();
		personId = person.getPersonId();
		politicalFace = person.getPoliticalFace();
		position = person.getPosition();
		sex = person.getSex();
		techlevel = person.getTechlevel();
		workerUser = person.getWorkerUser();
		workyear = person.getWorkyear();
		phoneNo = person.getPhoneNo() == null ? "" : person.getPhoneNo();
	}
%>
<html>
<head>
	<title>员工基本信息</title>
	<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
	<link href="../../css/table.css" rel="stylesheet" type="text/css">
	<link href="../../css/calendar.css" rel="stylesheet" type="text/css">
	<link href="../../css/webTree.css" rel="stylesheet" type="text/css">
	<script type="text/javascript" src="../../js/calendar.js"></script>
	<script type="text/javascript" src="../../js/common.js"></script>
	<script type="text/javascript">
	   function init() {
	   		if("" != "<%=personInfoId%>") { // 修改
		   		infoForm.name.value = "<%=name%>";
		   		infoForm.idNumber.value = "<%=idNumber%>";
		   		infoForm.sex.value = "<%=sex%>";
		   		infoForm.birthPlace.value = "<%=birthPlace%>";
		   		infoForm.national.value = "<%=national%>";
		   		infoForm.birthDate.value = "<%=birthDate%>";
		   		infoForm.bloodType.value = "<%=bloodType%>";
		   		infoForm.workerUseage.value = "<%=workerUser%>";
		   		infoForm.joinWay.value = "<%=joinWay%>";
		   		infoForm.hukouPlace.value = "<%=hukouPlace%>";
		   		infoForm.politicalFace.value = "<%=politicalFace%>";
		   		infoForm.nativePlace.value = "<%=nativePlace%>";
		   		infoForm.deptname.value = "<%=deptName%>";
		   		infoForm.deptId.value = "<%=deptId%>";
		   		infoForm.adminlevel.value = "<%=adminlevel%>";
		   		infoForm.techlevel.value = "<%=techlevel%>";
		   		infoForm.position.value = "<%=position%>";
		   		infoForm.workyear.value = "<%=workyear%>";
		   		infoForm.joinWorkyear.value = "<%=joinWorkYear%>";
		   		infoForm.highestDegree.value = "<%=highestDigree%>";
		    }
	   }
	   
	   	   // 提交
	   function doSubmit(){
	   		if(validate()){
	   			return;
	   		}
		 	if("" == "<%=personInfoId%>") {
		 		infoForm.actionType.value = "add";
			}else {
		 		infoForm.actionType.value = "modifyBaseInfo";
		 		infoForm.personId.value = "<%=personInfoId%>";
			}
		 	infoForm.submit();
	   }
	   
	   function validate(){
	   		if(infoForm.name.value == ""){
	   			alert("姓名不能为空！");
	   			return true;
	   		}
	   		if(infoForm.deptId.value == ""){
	   			alert("所属单位不能为空！");
	   			return true;
	   		}
	   		
	   		if(infoForm.name.value.length > 50){
   				alert("姓名不能超过50个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.idNumber.value.length > 50){
   				alert("身份证不能超过50个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.birthPlace.value.length > 50){
   				alert("出生地不能超过50个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.national.value.length > 20){
   				alert("民族不能超过20个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.workerUseage.value.length > 20){
   				alert("用工性质不能超过20个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.joinWay.value.length > 20){
   				alert("参加工作途径不能超过20个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.hukouPlace.value.length > 100){
   				alert("户口所在地不能超过100个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.politicalFace.value.length > 20){
   				alert("政治面貌不能超过20个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.nativePlace.value.length > 100){
   				alert("籍贯不能超过100个字！");
   				return true;
	   	    }
	   		
	   		if(infoForm.phoneNo.value.length > 20){
   				alert("手机号不能超过20个字！");
   				return true;
	   	    }
	   		return false;
	   }
	   
	   function selectNode(id, title, level){
	   		if(!validateDept(id, level)){
	   			alert("您当前的权限只能创建属于：["+title+"]单位的员工");
	   			return;
	   		}
			currTreeInputObj.value = title;
			currTreeInputObj.nextSibling.value = id;
			var treeFrame = document.getElementById("treeFrame");
			treeFrame.style.display = "none";
		}
	   function validateDept(deptId, deptLevel){
	   		if("<%=assDeptLevel%>" == 1 || "<%=assDeptLevel%>" == 0){//大队管理员或系统管理员
	   		    return true;
	   		}else if("<%=assDeptLevel%>" == 2){//中队管理员
	   		    if("<%=assDeptId%>" == deptId){
	   		    	return true;
	   		    }else if("<%=assDeptLevel%>" == deptLevel - 1){
	   		   		return true; 
	   		    }else{
	   		    	return false;
	   		    }
	   		}else{
	   			return false;
	   		}
	   }
	</script>
</head>
<body  rightmargin="0" bottommargin="0" leftmargin="0" topmargin="0" onclick="clickBody();" style="overflow: auto;" onload="init();">
 	<form name="infoForm" action="personManage_action.jsp" target="actionFrame" method="post">
	<input type="hidden" name="infoType" value="baseInfo">
	<input type="hidden" name="personId" value="">
	<input type="hidden" name="actionType" value="">
	<table class="personDataTable" style="width: 985px;table-layout: fixed;" cellpadding="0" cellspacing="0">
		<col width="9%">
		<col width="20%">
		<col width="9%">
		<col width="15%">
		<col width="9%">
		<col width="15%">
		<col width="9%">
		<col width="19%">
		<tr height="20px">
			<td colspan="8" align="right" style="padding-right: 22px;border: none;"><img title="保存基本信息" src="../../img/btn_save.gif" style="cursor: hand;" onclick="doSubmit();"></td>
		</tr>
		<tr height="25px">
			<td class="field">
				姓名
			</td>
			<td>
				<input type="text" name="name">
			</td>
			<td class="field">
				身份证
			</td>
			<td>
				<input type="text" name="idNumber">
			</td>
			<td class="field">
				性别
			</td>
			<td>
				<select name="sex">
				   <%
                   		for(SexType type: SexType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
			<td class="field">
				出生地
			</td>
			<td>
				<input type="text" name="birthPlace">
			</td>
		</tr>
		
		<tr height="25px">
			<td class="field">
				民族
			</td>
			<td>
				<input type="text" name="national">
			</td>
			<td class="field">
				出生日期
			</td>
			<td>
				<input name="birthDate" type="text" style="width: 200;cursor: hand;" id="time1" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('time1', 'y-mm-dd');">
			</td>
			<td class="field">
				血型
			</td>
			<td>
				<select name="bloodType">
				   <%
                   		for(BloodType type: BloodType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
			<td class="field">
				用工性质
			</td>
			<td>
				<input type="text" name="workerUseage">
			</td>
		</tr>
		
		<tr height="25px">
			<td class="field">
				参加工作途径
			</td>
			<td>
				<input type="text" name="joinWay">
			</td>
			<td class="field">
				户口所在地
			</td>
			<td>
				<input type="text" name="hukouPlace">
			</td>
			<td class="field">
				政治面貌
			</td>
			<td>
				<input type="text" name="politicalFace">
			</td>
			<td class="field">
				籍贯
			</td>
			<td>
				<input type="text" name="nativePlace">
			</td>
		</tr>
		
		<tr>
			<td class="field">
				所属单位
			</td>
			<td>
				<span class="treeSpan" onclick="showTree(this,'../common/deptTree.jsp',180, true);" treeSelect="true">
					<input name="deptname" nodeId="" id="deptTreeInput" value="" 
						style="width: 174px;" readonly="readonly" 
						treeSelect="true"><input name="deptId" value="" type="hidden">
				</span>
			</td>
			<td class="field">
				行政级别
			</td>
			<td>
				<select name="adminlevel">
				   <%
                   		for(AdministrationDegreeType type: AdministrationDegreeType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
			<td class="field">
				技术级别
			</td>
			<td>
				<select name="techlevel">
				   <%
                   		for(TechnicDegreeType type: TechnicDegreeType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
			<td class="field">
				职务
			</td>
			<td>
				<select name="position">
				   <%
                   		for(PositionType type: PositionType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
		</tr>
		
		<tr height="25px">
			<td class="field">
				参加工作时间
			</td>
			<td colspan="1">
				<input name="workyear" type="text" style="width: 200;cursor: hand;" id="time2" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('time2', 'y-mm-dd');">
			</td>
			<td class="field">
				最高学历
			</td>
			<td>
				<select name="highestDegree">
				   <%
                   		for(DegreeType type: DegreeType.getMembers()){
                   %>			
                   		<option value="<%= type.value() %>"><%= type.title()%></option>
                   <%
                   		}
                   %>
				</select>
			</td>
			<td class="field">
				进入本单位工作时间
			</td>
			<td>
				<input name="joinWorkyear" type="text" style="width: 200;cursor: hand;" id="time3" onClick="return showCalendar(this.id, 'y-mm-dd');" readonly="readonly"><img 
									src="../../img/tip_calender.gif" style="cursor: hand;" width="16" height="16" onClick="return showCalendar('time3', 'y-mm-dd');">
			</td>
			<td class="field">
				手机号
			</td>
			<td>
				<input name="phoneNo" value="<%=phoneNo %>"/>
			</td>
		</tr>
	</table>
	</form>
	<iframe src="#" frameborder="0" id="treeFrame" name="frame" style="display: none;position: absolute;"></iframe>
	<iframe src="#" name="actionFrame" style="display: none;"></iframe>
</body>
</html>